﻿using OrderingPlatform.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace OrderingPlatform.WebUI.Controllers
{
    public class ErrorController : Controller
    {
        //
        // GET: /Error/

        public ActionResult Index()
        {
            var model = new ErrorModel();
            var httpException = RouteData.Values["httpException"] as HttpException;
            var httpCode = (httpException == null) ? 500 : httpException.GetHttpCode();
            switch (httpCode)
            {
                case 403:
                    model.Heading = "403禁止访问";
                    model.Message = "你没有访问此页面的权限，请联系管理员.<br/>";
                    break;
                case 404:
                    model.Heading = "404你访问的页面不存在";
                    model.Message = "找不到你要访问的页面.";
                    break;
                case 500:
                default:
                    model.Heading = "500未知错误";
                    model.Message = "对不起, 发生一些未知错误，错误已记录，我们会尽快修复！.";
                    break;
            }
            if (httpException != null && httpException.InnerException != null)
            {
                model.Message += "<br/>" + httpException.InnerException.Message + "<br/>" + httpException.InnerException.Source + "<br/>" + httpException.InnerException.StackTrace;
            }
            Response.TrySkipIisCustomErrors = true;
            return View(model);
        }

    }
}
